<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleOpenScreenAll"
        >亮屏</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleCloseScreenAll"
        >息屏</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchRestart"
        >重启</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchPowerOff"
        >关机</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchOpsOn"
        >开启PC</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchOpsOff"
        >关闭PC</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchMute"
        >静音</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleBatchUnMute"
        >解除静音</el-button>
      </el-col>
    <el-col :span="1.5">
      <el-select v-model="source" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
          >
        </el-option>
      </el-select>
      <el-button @click="handleSource">切换信号源</el-button>
    </el-col>

    <el-col :span="1.5">
      <el-input width="50"
        v-model="voice"
        :style="{width: '200px'}"
        placeholder="请输入音量"
        clearable
        @keyup.enter.native="handleQuery"
      />
      <el-button @click="handleVoice">修改音量</el-button>
    </el-col>

    <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <el-table v-loading="loading" height="700px" :data="smartList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备编号" align="center" prop="deviceNo" />
      <el-table-column label="屏幕状态" align="center" prop="screenStatus" >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.screenStatus" :active-value="true" :inactive-value="false" @change="handlescreenStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="电脑状态" align="center" prop="opsStatus" >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.opsStatus" :active-value="true" :inactive-value="false" @change="handleopsStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="静音状态" align="center" prop="muteStatus" >
        <template slot-scope="scope">
          <el-switch v-model="scope.row.muteStatus" :active-value="true" :inactive-value="false" @change="handlemuteStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="音量大小" align="center" prop="voice" />
      <el-table-column label="信号源" align="center" prop="source" />
      <el-table-column label="操作" width="300" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateSource(scope.row)"
          >切换信号源</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateVoice(scope.row)"
          >修改音量</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleRestart(scope.row)"
          >重启</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCloseSmart(scope.row)"
          >关机</el-button>

        </template>
      </el-table-column>
    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      :page.sync="queryParams.pageNum"-->
<!--      :limit.sync="queryParams.pageSize"-->
<!--      @pagination="getList"-->
<!--    />-->
    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item v-if="sourceFlag" label="切换信号" prop="source">
              <el-select v-model="form.source" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item v-if="voiceFlag" label="音量" prop="voice">
              <el-input v-model="form.voice" placeholder="请输入音量" />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  batchMute,
  batchOpsOn,
  batchPowerOff,
  batchRestart, batchUnMute, batchVoice,
  closeScreenAll,
  openScreenAll,
  smartScreenList,
  updateSourceALl,
  updateStatus
} from "@/api/system/operationSmart.js";
import {changeUserStatus} from "@/api/system/user";
import {addNotice, getNotice, updateNotice} from "@/api/system/notice";

export default {
  name: "Loan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 音量输入框
      voiceFlag: false,
      sourceFlag: false,
      // 选中数组
      deviceNos: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公司管理表格数据
      smartList: [],
      // 日期范围
      dateRange: [],
      // 总借款未还信息
      allLoanMoney: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        borrower: null,
        dateRange: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
    source:null,
    voice:null,
    options:[
      {value:"ANDROID",label:'ANDROID'},
      {value:"HDMI1",label:'HDMI1'},
      {value:"VGA1",label:'VGA1'},
      {value:"PC",label:'PC'}
    ]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公司管理列表 */
    getList() {
      this.loading = true;
      smartScreenList(this.queryParams).then(response => {
        this.smartList = response.data;
        this.loading = false;
        console.log(this.smartList);
        // this.smartList=[{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1},{"deviceName":1}]

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deviceNo: null,
        source: null,
        voice: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 批量修改信号源
    handleSource(){
      const list = this.deviceNos
      const data ={
        source:this.source,
        deviceNos:list
      }
      console.log('wwww',data)
      updateSourceALl(data).then(res =>{
        this.$modal.msgSuccess("修改信号源成功");
        this.getList();
      })
    },
    // 批量修改音量
    handleVoice(){
      const list = this.deviceNos
      const data ={
        voice:this.voice,
        deviceNos:list
      }
      console.log('wwww',data)
      batchVoice(data).then(res =>{
        this.$modal.msgSuccess("修改音量成功");
        this.getList();
      })
    },
    // 批量亮屏
    handleOpenScreenAll() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要亮屏吗？').then(function() {

        return openScreenAll(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量息屏
    handleCloseScreenAll() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要息屏吗？').then(function() {return closeScreenAll(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量重启
    handleBatchRestart() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要重启智慧屏吗？').then(function() {
        return batchRestart(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量关机
    handleBatchPowerOff() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要关机吗？').then(function() {
        return batchPowerOff(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量开启PC
    handleBatchOpsOn() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要开启PC吗？').then(function() {
        return batchOpsOn(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量关闭PC
    handleBatchOpsOff() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要关闭PC吗？').then(function() {
        return batchOpsOff(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 批量静音
    handleBatchMute() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要静音吗？').then(function() {
        return batchMute(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    //批量解除静音
    handleBatchUnMute() {
      const list = this.deviceNos;
      console.log('list',list)
      const data ={
        deviceNos:list
      }
      this.$modal.confirm('确认要静音吗？').then(function() {
        return batchUnMute(data);
      }).then(() => {
        this.$modal.msgSuccess("操作成功");
        this.getList();
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // this.row = selection
      this.deviceNos = selection.map(item => item.deviceNo)
      console.log("======",this.deviceNos)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    // 修改电脑状态
    handleopsStatusChange(row) {
      let text = row.opsStatus === true ? "开启" : "关闭";
      this.$modal.confirm('确认要"' + text + '""' + row.deviceNo + '"智慧屏PC吗？').then(function() {
        const deviceNo = row.deviceNo
        const opsStatus = row.opsStatus
        const data ={deviceNo,opsStatus}
        return updateStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.opsStatus = row.opsStatus === "0" ? "1" : "0";
      });
    },

    // 修改屏幕状态
    handlescreenStatusChange(row) {
      let text = row.screenStatus === true ? "亮屏" : "息屏";
      this.$modal.confirm('确认要"' + text + '""' + row.deviceNo + '"智慧屏吗？').then(function() {
        const deviceNo = row.deviceNo
        const screenStatus = row.screenStatus
        const data ={deviceNo,screenStatus}
        return updateStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.screenStatus = row.screenStatus === true ? false : true;
      });
    },
    // 重启
    handleRestart(row) {
      this.$modal.confirm('确认要重启' + row.deviceNo + '"智慧屏吗？').then(function() {
        const deviceNo = row.deviceNo
        const restart = true
        const data ={deviceNo,restart}
        return updateStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === true ? false : true;
      });
    },
// 关机
    handleCloseSmart(row) {
      this.$modal.confirm('确认要关机' + row.deviceNo + '"智慧屏吗？').then(function() {
        const deviceNo = row.deviceNo
        const powerStatus = true
        const data ={deviceNo,powerStatus}
        return updateStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === true ? false : true;
      });
    },


    /** 单个修改信号源按钮操作 */
    handleUpdateSource(row) {
      this.reset();
      this.sourceFlag=true;
      this.voiceFlag=false;
      this.form.deviceNo = row.deviceNo;
      this.form.source = row.source;
      this.open = true;
      this.title = "修改信号源";

    },
    /** 修改音量按钮操作 */
    handleUpdateVoice(row) {
      this.reset();
      this.sourceFlag=false;
      this.voiceFlag=true;
      this.form.deviceNo = row.deviceNo;
      this.form.voice = row.voice;
      this.open = true;
      this.title = "修改音量";
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.deviceNo != undefined) {
            updateStatus(this.form).then(res =>{
              this.$modal.msgSuccess("修改信号源成功");
              this.open = false;
              this.getList();
            })
          }
        }
      });
    },

 // 修改静音状态
    handlemuteStatusChange(row) {
      let text = row.muteStatus === true ? "静音" : "解除静音";
      this.$modal.confirm('确认要"' + text + '""' + row.deviceNo + '"智慧屏吗？').then(function() {
        const deviceNo = row.deviceNo
        const muteStatus = row.muteStatus
        const data ={deviceNo,muteStatus}
        return updateStatus(data);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.muteStatus = row.muteStatus === true ? false : true;
      });
    },


  }
};
</script>

